package com.linkage.educloud.ah.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mr'Tang on 2018/12/18.
 */

public class StudyTypeBean implements Serializable{
    private int id;
    private String name;
    private List<SubjectBean> subjects;
    private List<SubjectBean> ress;

    public static ArrayList<StudyTypeBean> fromJSONObject(JSONObject json) {
        ArrayList<StudyTypeBean> typeList = new ArrayList<>();
        if (json != null && json.has("grades")) {
            try {
                JSONArray jar = json.getJSONArray("grades");
                for (int i = 0; i < jar.length(); i++) {
                    JSONObject obj = jar.getJSONObject(i);
                    StudyTypeBean type = new StudyTypeBean();
                    type.id = obj.optInt("id");
                    type.name = obj.optString("name");
                    type.subjects = SubjectBean.fromJSONObject(obj);
                    typeList.add(type);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return typeList;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<SubjectBean> getSubjects() {
        return subjects;
    }

    public void setSubjects(List<SubjectBean> subjects) {
        this.subjects = subjects;
    }

    public List<SubjectBean> getRess() {
        return ress;
    }

    public void setRess(List<SubjectBean> ress) {
        this.ress = ress;
    }
}
